﻿using System;

namespace SeoulOpenApi.Subway
{
    public class SubwayArrivalService : BaseService
	{
        public SubwayArrivalService() : this(null, null) { }

        /// <summary>
		/// 서울시 API 서비스
		/// </summary>
		/// <param name="userId">서울시 API접속 ID</param>
		/// <param name="authKey">서울시로부터 발급받은 인증키</param>
		/// <remarks>인증키 발급: http://mobile.openapi.seoul.go.kr/ </remarks>
        public SubwayArrivalService(string userId, string authKey)
        {
            base.UserID = userId;
            base.AuthKey = authKey;
        }


        // protected SoapData getSoapData(SeoulService serviceType)
        protected override SoapData  getSoapData(string serviceType)
        {
            SoapData soap = new SoapData { Address = new Uri(ApiUrlPrefix + "SubwayArriveService?wsdl", UriKind.Absolute) };

            switch (serviceType)
            {
                // 역외부코드로 지하철역별 열차 시간표 정보 검색
                case "searchTimeTableListByFrCode":
                    soap.Name = "searchTimeTableListByFrCode";
                    soap.Description = "역외부코드로 지하철역별 열차 시간표 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchTimeTableListByFrCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:frCode>{0}</ns3:frCode>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchTimeTableListByFrCode>";
                    break;

                // 역코드로 지하철역별 열차 시간표 정보 검색
                case "searchTimeTableListByStationCd":
                    soap.Name = "searchTimeTableListByStationCd";
                    soap.Description = "역코드로 지하철역별 열차 시간표 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchTimeTableListByStationCd xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:stationCd>{0}</ns3:stationCd>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchTimeTableListByStationCd>";
                    break;

                // 역외부코드로 지하철역별 열차 도착 정보 검색
                case "searchSubwayArriveListByFrCode":
                    soap.Name = "searchSubwayArriveListByFrCode";
                    soap.Description = "역외부코드로 지하철역별 열차 도착 정보 검색";
                    soap.SoapBody = 
                        "<ns3:searchSubwayArriveListByFrCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:frCode>{0}</ns3:frCode>" +
                            "<ns3:forGubun>{1}</ns3:forGubun>" +
                        "</ns3:searchSubwayArriveListByFrCode>";
                    break;

                // 역코드로 지하철역별 열차 도착 정보 검색 
                case "searchSubwayArriveListByStationCd":
                    soap.Name = "searchSubwayArriveListByStationCd";
                    soap.Description = "역코드로 지하철역별 열차 도착 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchSubwayArriveListByStationCd xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:stationCd>{0}</ns3:stationCd>" +
                            "<ns3:forGubun>{1}</ns3:forGubun>" +
                        "</ns3:searchSubwayArriveListByStationCd>";
                    break;

                // 역외부코드로 2호선 지하철역별 열차 도착 정보 검색
                case "searchSubwayArriveLine2ListByFrCode":
                    soap.Name = "searchSubwayArriveLine2ListByFrCode";
                    soap.Description = "역외부코드로 2호선 지하철역별 열차 도착 정보 검색";
                    soap.SoapBody =
                    "<ns3:searchSubwayArriveLine2ListByFrCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                        "<ns3:frCode>{0}</ns3:frCode>" +
                        "<ns3:forGubun>{1}</ns3:forGubun>" +
                    "</ns3:searchSubwayArriveLine2ListByFrCode>";
                    break;

                // 역코드로 2호선 지하철역별 열차 도착 정보 검색
                case "searchSubwayArriveLine2ListByStationCd":
                    soap.Name = "searchSubwayArriveLine2ListByStationCd";
                    soap.Description = "역코드로 2호선 지하철역별 열차 도착 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchSubwayArriveLine2ListByStationCd xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:stationCd>{0}</ns3:stationCd>" +
                            "<ns3:forGubun>{1}</ns3:forGubun>" +
                        "</ns3:searchSubwayArriveLine2ListByStationCd>";
                    break;

                // 역외부코드로 지하철역별 첫차/막차 시간 정보 검색
                case "searchFirstLastSubwayListByFrCode":
                    soap.Name = "searchFirstLastSubwayListByFrCode";
                    soap.Description = "역외부코드로 지하철역별 첫차/막차 시간 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchFirstLastSubwayListByFrCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:frCode>{0}</ns3:frCode>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchFirstLastSubwayListByFrCode>";
                    break;

                // 역코드로 지하철역별 첫차/막차 시간 정보 검색
                case "searchFirstLastSubwayListByStationCd":
                    soap.Name = "searchFirstLastSubwayListByStationCd";
                    soap.Description = "역코드로 지하철역별 첫차/막차 시간 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchFirstLastSubwayListByStationCd xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:stationCd>{0}</ns3:stationCd>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchFirstLastSubwayListByStationCd>";
                    break;


                // 열차별 경유 지하철역 도착시간 정보 검색
                case "searchViaStationListByTrainCode":
                    soap.Name = "searchViaStationListByTrainCode";
                    soap.Description = "열차별 경유 지하철역 도착시간 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchViaStationListByTrainCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:trainCode>{0}</ns3:trainCode>" +
                            "<ns3:forGubun>{1}</ns3:forGubun>" +
                            "<ns3:dayGubun>{2}</ns3:dayGubun>" +
                        "</ns3:searchViaStationListByTrainCode>";
                    break;

                // 역외부코드로 막차시간표 정보 검색
                case "searchLastTimeTableListByFrCode":
                    soap.Name = "searchLastTimeTableListByFrCode";
                    soap.Description = "역외부코드로 막차시간표 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchTimeTableListByFrCode xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:frCode>{0}</ns3:frCode>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchTimeTableListByFrCode>";
                    break;

                // 역코드로 막차시간표 정보 검색
                case "searchLastTimeTableListByStationCd":
                    soap.Name = "searchLastTimeTableListByStationCd";
                    soap.Description = "역코드로 막차시간표 정보 검색";
                    soap.SoapBody =
                        "<ns3:searchTimeTableListByStationCd xmlns:ns3='http://service.arrive.subway.openapi.ubizvalley.com'>" +
                            "<ns3:stationCd>{0}</ns3:stationCd>" +
                            "<ns3:dayGubun>{1}</ns3:dayGubun>" +
                            "<ns3:forGubun>{2}</ns3:forGubun>" +
                        "</ns3:searchTimeTableListByStationCd>";
                    break;
            }

            // 해당 서비스가 없는 경우
            if (String.IsNullOrEmpty(soap.Name))
                throw new Exception(serviceType + " not found.");

            return soap;
        }
	}

    //public enum SeoulService 
    //{ 
    //    searchTimeTableListByFrCode,
    //    searchTimeTableListByStationCd,
    //    searchSubwayArriveListByFrCode,
    //    searchSubwayArriveListByStationCd,
    //    searchSubwayArriveLine2ListByFrCode,
    //    searchSubwayArriveLine2ListByStationCd,
    //    searchFirstLastSubwayListByFrCode,
    //    searchFirstLastSubwayListByStationCd,
    //    searchViaStationListByTrainCode,
    //    searchLastTimeTableListByFrCode,
    //    searchLastTimeTableListByStationCd
    //}
}
